package com.lc.pianostudent.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.activity.AboutActivity;
import com.lc.pianostudent.activity.EverydayAnswerActivity;
import com.lc.pianostudent.activity.FeedBackActivity;
import com.lc.pianostudent.activity.NavigationActivity;
import com.lc.pianostudent.activity.PersonInfoActivity;
import com.lc.pianostudent.activity.PianoListActivity;
import com.lc.pianostudent.activity.PianoRecordActivity;
import com.lc.pianostudent.activity.SettingActivity;
import com.lc.pianostudent.activity.VipActivity;
import com.lc.pianostudent.activity.WebActivity;
import com.lc.pianostudent.conn.Conn;
import com.lc.pianostudent.conn.PostGetuser;
import com.zcx.helper.app.AppCallBack;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2018/4/18.
 */

public class MineFragment extends BaseFragment implements View.OnClickListener{

    @BoundView(value = R.id.person_information,isClick = true) private RelativeLayout person_information;
    @BoundView(value = R.id.setting,isClick = true) private RelativeLayout setting;
    @BoundView(value = R.id.feed_back,isClick = true) private RelativeLayout feed_back;
    @BoundView(value = R.id.help,isClick = true) private RelativeLayout help;
    @BoundView(value = R.id.about,isClick = true) private RelativeLayout about;
    @BoundView(value = R.id.vip,isClick = true) private RelativeLayout vip;
    @BoundView(value = R.id.piano_diary,isClick = true) private RelativeLayout piano_diary;
    @BoundView(value = R.id.piano_list,isClick = true) private RelativeLayout piano_list;

    @BoundView(R.id.name) private TextView name;
    @BoundView(R.id.image) private CircleImageView circleImageView;
    @BoundView(R.id.remark) private TextView remark;
    private PostGetuser postGetuser = new PostGetuser(new AsyCallBack<PostGetuser.PostGetuserInfo>() {


        @Override
        public void onSuccess(String toast, int type, Object o, PostGetuser.PostGetuserInfo postGetuserInfo) throws Exception {

            name.setText(postGetuserInfo.name);
            remark.setText(postGetuserInfo.person);
            GlideLoader.getInstance().get(postGetuserInfo.avatar,circleImageView,R.mipmap.new_head);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = BoundViewHelper.boundView(this, inflater.inflate(R.layout.fragment_mine, null));
        setAppCallBack(new CallBack());
        initView();
        return  view;
    }

    private void initView(){
        if(BaseApplication.BasePreferences.getIsLogin()){
            postGetuser.user_id = BaseApplication.BasePreferences.readUID();
            postGetuser.type = "0";
            postGetuser.execute();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.person_information:
                startVerifyActivity(PersonInfoActivity.class);
                break;

            case R.id.setting:
                startVerifyActivity(SettingActivity.class);
                break;

            case R.id.feed_back:
                startVerifyActivity(FeedBackActivity.class);
                break;

            case R.id.help:
//                startVerifyActivity(HelpActivity.class);
                startActivity(new Intent(getContext(), WebActivity.class).putExtra("url", Conn.SERVICE+Conn.WEB_SHOW_HELP).putExtra("title", "帮助"));

                break;

            case R.id.about:
//                startVerifyActivity(AboutActivity.class);
                startActivity(new Intent(getContext(), AboutActivity.class).putExtra("url", Conn.SERVICE+Conn.WEB_SHOW_ABOUT).putExtra("title", "关于"));

                break;

            case R.id.vip:
                startActivity(new Intent(getContext(),VipActivity.class).putExtra("from","2"));
                break;

            case R.id.piano_diary:
                startVerifyActivity(PianoRecordActivity.class);
                break;

            case R.id.piano_list:
                startVerifyActivity(PianoListActivity.class);
                break;
        }
    }

    public class CallBack implements AppCallBack {

        public void onRefresh() {
            postGetuser.user_id = BaseApplication.BasePreferences.readUID();
            postGetuser.type = "0";
            postGetuser.execute(false);

        }

    }
}
